﻿#include "usart.h"


/**
 * @brief usart0 configure
 * @param baudrate baud rate
 */
void usart_config(uint32_t baudrate)
{
    /* setup usart0 clock */
    rcu_periph_clock_enable(RCU_USART0);
    /* setup GPIOA clock */
    rcu_periph_clock_enable(RCU_GPIOA);

    /* configure Tx(PA9) and Rx(PA10) pin */
    gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
    gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);

    /* configure USART0 */
    usart_deinit(USART0);
    usart_baudrate_set(USART0, baudrate);
    usart_word_length_set(USART0, USART_WL_8BIT);
    usart_stop_bit_set(USART0, USART_STB_1BIT);

    /* configure USART0 to normal mode */
    usart_enable(USART0);
    usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
    usart_receive_config(USART0, USART_RECEIVE_ENABLE);

    /* configure USART0 interrupt */
    // usart_interrupt_enable(USART0, USART_INT_RBNE);

    /* configure USART0 interrupt request passage */
    nvic_irq_enable(USART0_IRQn, 6, 0); // priority to 6
}

/**
 * @brief rewrite usart0 receive complete interrupt callback function
 * @param usart_periph usart peripheral
 */
void usart_rx_cplt_callbake_it(uint32_t usart_periph)
{
    if(USART0 == usart_periph)
    {
    }
}
